package de.tabuma.wsdl2xform.xform.controller;

import de.tabuma.wsdl2xform.xform.entity.*;
import de.tabuma.wsdl2xform.xform.logik.*;
import de.tabuma.wsdl2xform.xform.constants;
import de.tabuma.lib.tabumacontroller;
import de.tabuma.soap.entity.bpel.*;
import de.tabuma.soap.entity.soap.*;
import de.tabuma.soap.entity.wsdl.*;
import de.tabuma.soap.entity.xsd.*;
import java.io.*;

import java.util.*;
import java.util.logging.*;
import java.lang.reflect.*;

import javax.servlet.*;
import javax.servlet.http.*;

import com.google.appengine.api.users.*;

/**
 *
 * @author $Author: alefen $
 * @version $Revision: 1.1 $
 * @since $Date: 2009/12/30 01:10:56 $
 */
public class projectPage2 extends tabumacontroller {

    private static Logger log = Logger.getLogger(projectPage2.class.getName());

    public projectPage2(String servlet, Hashtable parameter) {
        super(servlet, parameter);
    }

    public void navigate(ServletContext context, HttpServletRequest request, HttpServletResponse response, PrintWriter out) {
        try {
            if(request.getParameter(constants.NAV_NEXT_STEP)!=null) {
                log.fine(constants.NAV_NEXT_STEP+":true");
                UserService userService = UserServiceFactory.getUserService();
                User user = userService.getCurrentUser();

                long key = 0;
                if(request.getParameter(constants.T_DEFINITIONS_KEY)!=null) {
                    key = Long.valueOf(request.getParameter(constants.T_DEFINITIONS_KEY));
                }
                String name = request.getParameter(constants.PROJECT_NAME);
                String description = request.getParameter(constants.PROJECT_DESCRIPTION);
                String method = request.getParameter(constants.PROJECT_METHOD);
                String url = request.getParameter(constants.WSDL_URL);

                int id = ProjectFacade.doCreate(user.getEmail(), name, description, url, method, false, key);
                
                request.setAttribute(constants.XFORM_NAV,""+constants.NAV_SHOW_PROJECT);
                request.setAttribute(constants.PROJECT_ID, id);

                projectPage3 projectPage3 = new projectPage3(this.getServlet(), this.getParameter());
                projectPage3.navigate(context, request, response, out);

            }
            else {
                log.fine(constants.NAV_NEXT_STEP+":false");
                request.setAttribute(constants.XFORM_NAV,""+constants.NAV_SECOND_STEP);
                request.setAttribute(constants.T_DEFINITIONS_KEY,request.getParameter(constants.T_DEFINITIONS_KEY));
            }
        }
        catch(Exception e) {
            log.warning(e.getMessage());
        }
    }

}
